package com.huonan.jb.tools.fileuse.compare;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @Description TODO
 * @Author lxp
 * @Date 2022/9/29 下午3:46
 * @Version V1.0
 **/
@Slf4j
public class test2 {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        // 使用过滤器函数过滤偶数
        List<Integer> evenNumbers = filter(numbers, i -> i % 2 == 0);
        System.out.println(evenNumbers); // [2, 4, 6, 8, 10]

        // 使用过滤器函数过滤奇数
        List<Integer> oddNumbers = filter(numbers, i -> i % 2 != 0);
        System.out.println(oddNumbers); // [1, 3, 5, 7, 9]
    }

    public static <T> List<T> filter(List<T> list, Predicate<T> predicate) {
        return list.stream()
                .filter(predicate)
                .collect(Collectors.toList());
    }
}



